<script setup lang="ts">
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

// 获取主导航路由
const mainRoutes = router.options.routes[0].children || []

const handleMenuClick = (path: string) => {
  router.push(path)
}
</script>

<template>
  <div class="layout">
    <el-container>
      <el-aside width="64px">
        <div class="menu-sidebar">
          <el-menu
            :default-active="route.path"
            class="menu-bar"
            mode="vertical"
            :collapse="true"
            @select="handleMenuClick"
          >
            <el-menu-item v-for="item in mainRoutes" :key="item.path" :index="item.path">
              <el-icon>
                <component :is="item.meta?.icon" />
              </el-icon>
              <template #title>{{ item.meta?.name }}</template>
            </el-menu-item>
          </el-menu>
        </div>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<style scoped lang="scss">
.layout {
  height: 100vh;
  .el-container {
    height: 100%;
  }
  
  .menu-sidebar {
    height: 100%;
    background-color: var(--el-menu-bg-color);
    
    .menu-bar {
      height: 100%;
      border-right: none;
    }
  }

  .el-main {
    padding: 20px;
    background-color: var(--el-bg-color);
  }
}
</style>

